package acm;

import java.io.PrintStream;
import java.util.Scanner;

public class HeavyNumber
{
	static Scanner in = new Scanner(System.in);
	static PrintStream out = System.out;
	
	static Node max;

	static class Node
	{
		int time;
		int num;
		
		Node left;
		Node right;
		
		public Node(int num, int time)
		{
			this.time = time;
			this.num = num;
		}
		
		public void setLeft(Node node)
		{
			left = node;
		}
		
		public void setRight(Node node)
		{
			right = node;
		}
	}
	
	public static void main(String[] args)
	{
		for(int i=in.nextInt(); i>0; i--)
		{
			figure();
		}
	}

	private static void figure()
	{
		int i = in.nextInt();
		
		Node root = new Node(in.nextInt(), 1);
		
		for( --i; i>0; i--)
		{
			addLeaf(in.nextInt(), root);
		}
		
		max = new Node(0, 0);
		findMax(root);
		
		out.println(max.num + " " + max.time);
	}

	private static void findMax(Node root)
	{
		if ( root.left != null )
		{
			findMax(root.left);
		}
		
		if ( root.time > max.time )
			max = root;
		
		if ( root.right != null )
		{
			findMax(root.right);
		}
	}

	private static void addLeaf(int num, Node root)
	{
		if ( num > root.num )
		{
			if(root.right == null)
				root.setRight(new Node(num, 1));
			else
				addLeaf(num, root.right);
		}
		else if ( num == root.num )
		{
			root.time++;
		}
		else
		{
			if(root.left == null)
				root.setLeft(new Node(num, 1));
			else
				addLeaf(num, root.left);
		}
	}
}
